package com.gitee.chili.leisure.repository;

import com.gitee.chili.leisure.base.BaseRepository;
import com.gitee.chili.leisure.domain.EntryRoom;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

/**
 * EntryRoomRepository
 *
 * @author week solider
 * @since 2020.09.04
 */
public interface EntryRoomRepository  extends BaseRepository<Long, EntryRoom> {

    EntryRoom findByMember_IdAndStatus(Long memberId, Integer status);

    @Query(value = "select count(*) from entry_room where room_number = :roomNum and status = :status", nativeQuery = true)
    Integer selectPeopleNum(@Param("roomNum") Long roomNum, @Param("status") Integer status);

    @Query("update EntryRoom er set er.status = :status where er.member.id = :memberId")
    Integer updateStatusByMemberId(@Param("memberId") Long member, @Param("status") Integer status);

    List<EntryRoom> findByRoom_RoomNumAndStatus(Long roomNum, Integer status);
}
